app.controller("temController",function ($scope,$controller,temService,specService,brandService) {
    $controller("baseController",{$scope:$scope});
    $scope.temEntity={};
    $scope.list=[];
    $scope.entity={customAttributeItems:[]};
    //模糊查询
    $scope.search=function (page,rows) {

        temService.findPageService(page,rows,$scope.temEntity).success(
            function (data) {

                $scope.list=data.rows;
                $scope.paginationConf.totalItems=data.total;
            }
        )
    }
    //将json字符串转换成字符串展示
    $scope.toString=function (jsontoString,key) {
        //将json字符串转换为json对象
      if(jsontoString!=null){
          var json=JSON.parse(jsontoString);
          var value="";
          //遍历json对象并其进行判断如果大于0就拼接个逗号省去subString操作
          for(var i=0;i<json.length;i++){
              if(i>0){
                  value+=","
              }
              //根据字符串的key值进行拼接
              value+=json[i][key];
          }
          return value;
      }
        //定义一个变量用于拼接字符串

    }
    //实现select2插件
    $scope.brandList={
        data:[]
    }
    //得到brand列表
    $scope.findBrandList=function () {
        brandService.findBrandList().success(
            function (response) {

                $scope.brandList.data=response;
            }
        )
    }
    $scope.specList={
        data:[]
    }
    //得到规格列表
    $scope.findSpecList=function () {
        specService.findSpecList().success(
            function (response) {

                $scope.specList.data=response;
            }
        )
    }
    //实现添加
    $scope.save=function () {
        temService.saveService($scope.entity).success(
            function (data) {
                       if(data.success){

                           $scope.reloadList();

                       }else{
                           alert(data.message);
                           alert("添加失败");
                       }
              })
    }
        //删除
        $scope.delete=function () {
           temService.delService($scope.ids).success(
               function (data) {
                           if(data.success){
                               alert("删除成功");
                               $scope.reloadList();

                           }else{
                               alert("删除失败");
                           }
                     }
           )
        }
      //回显
     $scope.findOne=function (id) {
        debugger;
         temService.findOneService(id).success(
             function (data) {
                 debugger;
                 $scope.entity=data;
                 $scope.entity.specIds=JSON.parse($scope.entity.specIds);
                 $scope.entity.brandIds=JSON.parse($scope.entity.brandIds);
                 $scope.entity.customAttributeItems=JSON.parse($scope.entity.customAttributeItems);
             }
         )
     }
    $scope.xinzeng=function () {

        $scope.entity.customAttributeItems.push({});
    }
})